package org.jix.gbook.note.biz.consumer;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.jix.gbook.note.biz.constant.MQConstants;
import org.jix.gbook.note.biz.service.NoteService;
import org.springframework.stereotype.Component;

/**
 * @author stark
 * @date 2025/9/27 下午3:12
 * @description 删除本地笔记缓存消费者
 **/

@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "gbook_group", //group
        topic = MQConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE, //消费主题
        messageModel = MessageModel.BROADCASTING ) //广播模式
public class DeleteNoteLocalCacheConsumer implements RocketMQListener<String> {

    @Resource
    private NoteService noteService;

    @Override
    public void onMessage(String s) {
        Long noteId = Long.valueOf(s);
        log.info("## 消费者消费成功, noteId: {}", noteId);
        noteService.deleteNoteLocalCache(noteId);
    }
}
